package com.heima.mapper;

import com.heima.pojo.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface VmMapper {

    List<VendingMachine> selectVendingMachine(String inncerrCode);
    @Select("select * from tb_node where id = #{nodeId}")
    Node selectNodeByNodeID(Long nodeId);
    @Select("select * from tb_region where id = #{regionId}")
    Region selectRegionByRegionId(Long regionId);
    @Select("select * from tb_business where id = #{businessId}")
    Business selectBusinessById(Integer businessId);
    @Select("select * from tb_vm_type where type_id = #{vmType};")
    Type selectVMTypeByvmType(Integer vmType);
    @Select("select user_name from tb_user where id = #{createUserId}")
    String selectCreateName(Long createUserId);
    @Insert("insert into tb_vending_machine   (\n" +
            "        id,\n" +
            "        vm_type,\n" +
            "        inner_code,\n" +
            "        node_id,\n" +
            "        vm_status,\n" +
            "        last_supply_time,\n" +
            "        city_code,\n" +
            "        area_id,\n" +
            "        create_user_id,\n" +
            "        create_user_name,\n" +
            "        business_id,\n" +
            "        region_id,\n" +
            "        owner_id,\n" +
            "        owner_name,\n" +
            "        client_id,\n" +
            "        longitudes,\n" +
            "        latitude,\n" +
            "        create_time,\n" +
            "        update_time\n" +
            "    ) VALUES (\n" +
            "        #{id},\n" +
            "        #{vmType},\n" +
            "        #{innerCode},\n" +
            "        #{nodeId},\n" +
            "        #{vmStatus},\n" +
            "        #{lastSupplyTime},\n" +
            "        #{cityCode},\n" +
            "        #{areaId},\n" +
            "        #{createUserId},\n" +
            "        #{createUserName},\n" +
            "        #{businessId},\n" +
            "        #{regionId},\n" +
            "        #{ownerId},\n" +
            "        #{ownerName},\n" +
            "        #{clientId},\n" +
            "        #{longitudes},\n" +
            "        #{latitude},\n" +
            "        #{createTime},\n" +
            "        #{updateTime}\n" +
            "    )")
    void addVendingMachine(VendingMachine vendingMachine);
    @Select("select a.city_code from tb_area a left join tb_node n on a.ad_code = n.area_code where n.id = #{nodeId} ;")
    String selectCityCodeByNodeId(Long nodeId);
    @Select("select tb_node ")
    Long selectRegionId(Long nodeId);
}
